package com.eat.controller.user;

import com.eat.constant.JwtClaimsConstant;
import com.eat.dto.UserLoginDTO;
import com.eat.properties.JwtProperties;
import com.eat.properties.WeChatProperties;
import com.eat.result.Result;
import com.eat.service.UserService;
import com.eat.utils.JwtUtil;
import com.eat.vo.UserLoginVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/user/user")
@Slf4j
public class UserController {

    @Autowired
    private UserService userService;
    @Autowired
    private WeChatProperties weChatProperties;
    @Autowired
    private JwtProperties jwtProperties;
    @PostMapping("/login")
    public Result<UserLoginVO> login(@RequestBody UserLoginDTO userLoginDTO){

//        User user = userService.wxLogin(userLoginDTO);


        Map<String,Object> claim = new HashMap<>();
        claim.put(JwtClaimsConstant.USER_ID,1l);
        String jwt = JwtUtil.createJWT(jwtProperties.getUserSecretKey(), jwtProperties.getUserTtl(), claim);
        log.info("token:{}",jwt);
//        UserLoginVO userLoginVO = UserLoginVO.builder()
//                .id(user.getId())
//                .token(jwt)
//                .openid(user.getOpenid())
//                .build();
        UserLoginVO userLoginVO = UserLoginVO.builder()
                .id(1l)
                .token(jwt)
                .openid("abcdefg")
                .build();
        return Result.success(userLoginVO);
    }

}
